<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
//if (sizeof($catalog_active_category) > 0) {
//	echo "<h1>".$catalog_active_category['parent_title']."</h1>";
//}

	if (sizeof($pages) > 0) {
//		echo "<h2>Категории</h2>";
		echo "<div class='catalog-parent-items'>";
		echo "<div class='spike-top'></div>";
		echo "<div class='spike-bottom'></div>";
		echo "<div class='spike-left'></div>";
		echo "<div class='spike-right'></div>";
		foreach ($pages as $page) {
			echo "<div class='catalog-parent-item'>";
				echo "<div class='image'>";
//				if (sizeof($catalog_active_category) > 0) {
//					$parent_link = "/".$catalog_active_category['parent_curl']."/".$page['parent_curl']."/";
//				} else {
//					$parent_link = "/".$page['parent_curl']."/";
//				}
				$parent_link = "/catalog/category/".$page['parent_id']."/";
					echo "<a href='".$parent_link."'>";
						if ($page['parent_image'] != "" && file_exists("./uploads/catalog_parents/".$page['parent_id']."/small/".$page['parent_image'])) {
							$im = getimagesize("./uploads/catalog_parents/".$page['parent_id']."/small/".$page['parent_image']);
							$margin = round((120 - $im[1]) / 2);
							echo "<img src='/uploads/catalog_parents/".$page['parent_id']."/small/".$page['parent_image']."' alt='".$page['parent_title']."' title='".$page['parent_title']."' style='margin: ".$margin."px auto 0 auto;' />";
						} else {
							echo "<img src='/data/images/x.gif' alt='".$page['parent_title']."' title='".$page['parent_title']."' />";
						}
					echo "</a>";
				echo "</div>";
				echo "<div class='name'>";
					echo "<a href='".$parent_link."'>".$page['parent_title']."</a>";
//					echo "</a>";
					echo "<p>";
					$childs = $this->db->select()->from('catalog_parents')->where('parent_parent', $page['parent_id'])->where('parent_status', 1)->limit(3)->order_by('parent_order')->get()->result_array();
						if (sizeof($childs) > 0) {
							echo '<small>';
							foreach ($childs as $key=>$child) {
								echo "<a href='/catalog/category/".$child['parent_id']."/'>".$child['parent_title']."</a>";
								//echo $child['parent_title'];
								if($key != (count($childs)-1)){
									echo " , ";
								}
							}
							echo '</small>';
						}
					echo "</p>";
				echo "</div>";
			echo "</div>";
		}
		echo "</div>";
		echo "<br class='cc'/>";
	}
	if (sizeof($items) > 0) {
//		if ($paging) echo $paging;
//		echo "<h2 class='u-line'>Товары</h2>";
//		echo "<div class='orderpanel'>";
//			echo "<a class='".($order=='order'?"active":"")."' href='/".$url."/category/".$id."/?order=order&side=".($side=='asc'?"desc":"asc")."'>По порядку ".($side=="asc"?"&uarr;":"&darr;")."</a>&nbsp;";
//			echo "<a class='".($order=='price'?"active":"")."' href='/".$url."/category/".$id."/?order=price&side=".($side=='asc'?"desc":"asc")."'>По цене ".($side=="asc"?"&uarr;":"&darr;")."</a>&nbsp;";
//			echo "<a class='".($order=='code'?"active":"")."' href='/".$url."/category/".$id."/?order=code&side=".($side=='asc'?"desc":"asc")."'>По артиклу ".($side=="asc"?"&uarr;":"&darr;")."</a>&nbsp;";
//		echo "</div><br class='cc' />";
		if (sizeof($tags) > 0) {
		echo "<div class='tagspanel'>";
		echo "<ul>";
			$link = explode("?", $_SERVER['REQUEST_URI']);
			echo "<li class='catname ".($intag == ''?"active":"")."'><a href='".$link[0]."'>Все</a></li>";
				foreach ($tags as $tag) {

					if (urldecode($this->input->get('tag')) == $tag) $class = "active"; else $class = "";
					echo "<li class='".$class." blue-link'>";
						echo "<a href='".$link[0]."?tag=".urlencode($tag)."'>".$tag."</a>";
					echo "</li>";
				}

		echo "</ul><br class='cc' />";
		echo "</div>";
		}
		echo "<div>";
		foreach ($items as $item) {
			$data['item'] = $item;
			$this->load->view('modules/catalog/one_item', $data);
		}
		echo "</div>";
		echo "<br class='cc'/>";
		if ($paging) echo $paging;
	}

	if (sizeof($pages) <= 0 && sizeof($items) <= 0) {
		echo showmenotice('Категория пуста');
	}

//	if ($catalog_active_category['parent_desc'] != "") {
//		echo $catalog_active_category['parent_desc'];
//	}
	if($this->uri->segment(2) == 'category'){
		$slider = $this->slider_model->all($id,'hit');
		if(mb_strlen($slider) > 0){
			echo '<h2 class="slider_h2">Лидеры продаж</h2>';
			echo '<div class="big_center_slider">';
			echo $slider;
			echo '</div>';
		}
	}
?>